<?php

/**
 * Wave Framework <http://www.waveframework.com>
 * View Controller
 *
 * Wave Framework comes with a View Controller and a translations system that is used to build 
 * a website on Wave Framework. This View Controller is entirely optional and can be removed 
 * from a system if you plan to implement your own View Controller or simply use Wave Framework 
 * for API, without a website.
 *
 * @package    Tools
 * @author     Kristo Vaher <kristo@waher.net>
 * @copyright  Copyright (c) 2012, Kristo Vaher
 * @license    GNU Lesser General Public License Version 3
 * @tutorial   /doc/pages/guide_view.htm
 * @since      1.0.0
 * @version    3.6.9
 */

class WWW_controller_registerusers extends WWW_Factory {

	/**
	 * This method is called by Data Handler to render View contents based on values from 
	 * URL Controller.
	 *
	 * @param array $input input data sent to controller
	 * @input mixed input data from URL Controller output
	 * @return null
	 */
	  
	
	public function create_registeruser($data)
	{	
		//echo "<pre>";print_r($data);exit;
		$reason=array();
		if($data[is_association]==1 || $data[association_name]!="" || $data[association_email]!="" || $data[association_info]!="")
		{
		if($data['association_name']=='')
		{
			$reason['association_nameerror']="Association Name should contain some value";
			$status="fail";
		}
		if($data['association_email']=='')
		{
			$reason['association_emailerror']="Association Email should contain some value";
			$status="fail";
		}
		if($data['association_info']=='')
		{
			$reason['association_infoerror']="Association Info should contain some value";
			$status="fail";
		}	
		}
		if($data['user_name']=='')
		{
			$reason['user_nameerror']="Name should contain some value";
			$status="fail";
		}
		if($data['email']=='')
		{
			$reason['emailerror']="Email should contain some value";
			$status="fail";
		}
		if($data['password']=='')
		{
			$reason['passworderror']="Password should contain some value";
			$status="fail";
		}
		if($data['phone_number']=='')
		{
			$reason['phone_numbererror']="Phone Number should contain some value";
			$status="fail";
		}
		if($data['address_1']=='')
		{
			$reason['address_1error']="Address1 should contain some value";
			$status="fail";
		}
		if($data['state_id']=='')
		{
			$reason['stateerror']="State should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('registerusers');
		$result=$model->create_registeruser($data);
		//print_r($result);exit;
		return $this->resultTrue('result',$result);	
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	
	public function edit_registeruser($data)
	{	
		$reason=array();
		if($data[is_association]==1 || $data[association_name]!="" || $data[association_email]!="" || $data[association_info]!="")
		{
		if($data['association_name']=='')
		{
			$reason['association_nameerror']="Association Name should contain some value";
			$status="fail";
		}
		if($data['association_email']=='')
		{
			$reason['association_emailerror']="Association Email should contain some value";
			$status="fail";
		}
		if($data['association_info']=='')
		{
			$reason['association_infoerror']="Association Info should contain some value";
			$status="fail";
		}	
		}
		if($data['user_name']=='')
		{
			$reason['user_nameerror']="Name should contain some value";
			$status="fail";
		}
		if($data['email']=='')
		{
			$reason['emailerror']="Email should contain some value";
			$status="fail";
		}
		if($data['password']=='')
		{
			$reason['passworderror']="Password should contain some value";
			$status="fail";
		}
		if($data['phone_number']=='')
		{
			$reason['phone_numbererror']="Phone Number should contain some value";
			$status="fail";
		}
		if($data['address_1']=='')
		{
			$reason['address_1error']="Address1 should contain some value";
			$status="fail";
		}
		if($data['state_id']=='')
		{
			$reason['stateerror']="State should contain some value";
			$status="fail";
		}
		if($status!="fail")
		{
		$model=$this->getModel('registerusers');
		$result=$model->edit_registeruser($data);
		return $this->resultTrue('result',$result);
		}else
		{
			return $this->resultTrue('result',$reason);
		}
	}
	
	public function get_registeruser($data)
	{	
		$model=$this->getModel('registerusers');
		$result=$model->get_registeruser($data);
		
		return $this->resultTrue('result',$result);
	}
	public function delete_registeruser($data)
	{		
		$model=$this->getModel('registerusers');
		$deleted_info = $model->delete_registeruser($data);
		return $this->resultTrue('Delete modules Info',$deleted_info);
	}
	
	public function all_registerusers($data)
	{		//print_r($data);exit;
		$model=$this->getModel('registerusers');
		$modules_info = $model->all_registerusers($data);	
		return $this->resultTrue('All modules',$modules_info);		
	}
	public function get_users($data)
	{		//print_r($data);exit;
		$model=$this->getModel('registerusers');
		$modules_info = $model->get_users($data);	
		return $this->resultTrue('All modules',$modules_info);		
	}
	public function get_associationusers($data)
	{		//print_r($data);exit;
		$model=$this->getModel('registerusers');
		$modules_info = $model->get_associationusers($data);	
		return $this->resultTrue('All modules',$modules_info);		
	}
	public function get_states_list()
	{		//print_r($data);exit;
		$model=$this->getModel('registerusers');
		$modules_info = $model->get_states_list();	
		return $this->resultTrue('All modules',$modules_info);		
	}
	
}

?>